﻿using Microsoft.AspNetCore.Http;

namespace HttpClientStudy.UnitTest.HttpClients
{
    /// <summary>
    ///  SimpleHttpClient 测试类
    /// </summary>
    public class BaseHttpClientTest
    {
        private readonly ITestOutputHelper _logger;
        public BaseHttpClientTest(ITestOutputHelper outputHelper) 
        {
            _logger = outputHelper;
        }

        [Fact]
        public void Get_Test()
        {
            BaseHttpClient client = new BaseHttpClient();

            var result = client.Get(WebApiConfigManager.GetWebApiConfig().BaseUrl + "/api/Simple/GetAccount");

            Assert.NotNull(result);
            Assert.NotEmpty(result);
        }

        [Fact]
        public void GetJson_Test()
        {
            BaseHttpClient client = new BaseHttpClient();

            var result = client.GetJson<BaseResult<string>>(WebApiConfigManager.GetWebApiConfig().BaseUrl + "/api/Simple/GetAccount");

            Assert.NotNull(result);
            Assert.IsAssignableFrom<BaseResult>(result);
            Assert.Equal(1, result.Code);
            Assert.Contains("成功", result.Message);
            Assert.IsType<string>(result.Message);
            Assert.NotEmpty(result.Message);
        }

        [Fact]
        public void Study_Test()
        {
            BaseHttpClient client = new BaseHttpClient();

            var result = client.GetJson<BaseResult<string>>(WebApiConfigManager.GetWebApiConfig().BaseUrl + "/api/Simple/GetAccount");

            Assert.NotNull(result);
            Assert.IsAssignableFrom<BaseResult>(result);
            Assert.Equal(1, result.Code);
            Assert.Contains("成功", result.Message);
            Assert.IsType<string>(result.Message);
            Assert.NotEmpty(result.Message);
        }
    }
}
